#ifndef NANO_PACKAGE_H
#define NANO_PACKAGE_H
#include "../protocol/protocol.h"

#include <godot_cpp/core/binder_common.hpp>
#include <godot_cpp/classes/ref_counted.hpp>
#include <godot_cpp/variant/packed_byte_array.hpp>
namespace godot
{

class NanoPackage : public RefCounted {
    GDCLASS(NanoPackage, RefCounted)
protected:
    static void _bind_methods();
public:
    enum PackageType {
        TYPE_HANDSHAKE = 1,
        TYPE_HANDSHAKE_ACK = 2,
        TYPE_HEARTBEAT = 3,
        TYPE_DATA = 4,
        TYPE_KICK = 5
    };
public:
    PackageType type;
    PackedByteArray body;
	bool valid = true;//the package from decode have this
public:
    bool is_valid() const {
        return valid;
	}
public:
    PackageType get_type() const {
        return type;
    }
    void set_type(PackageType p_type) {
		type = p_type;
    }
    PackedByteArray get_body() const {
        return body;
    }
    void set_body(const PackedByteArray& p_body) {
		body = p_body;
    }
public:
    NanoPackage() = default;
    void initNanoPackage(Protocol::Package pkg) {
        type = static_cast<PackageType>(pkg.type);
        if (!pkg.body.empty()) {
            body.resize(pkg.body.size());
            for (size_t i = 0; i < pkg.body.size(); i++) {
                body[i] = pkg.body[i];
            }
        }
    }
};

}
VARIANT_ENUM_CAST(godot::NanoPackage::PackageType);
#endif